<template>
  <div style="width: 100%;height: 100vh;overflow: hidden">
    <div style="width: 400px;margin:150px auto ">
      <div style="color: #1254cb;font-size: 63px;text-align: center;padding:30px 30px 20px 30px;font-family: 'Pristina';font-weight: bold">Register</div>
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item prop="username">
          <el-input   v-model="form.username">
           <template #prefix>
             <el-icon style="color: brown"><User/></el-icon>
           </template>
          </el-input>
        </el-form-item>
<!--        prop和下面验证一一对应-->
        <el-form-item prop="password">
          <el-input   v-model="form.password" show-password>
            <template #prefix>
              <el-icon style="color: brown"><Lock/></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="confirm">
          <el-input   v-model="form.confirm" show-password>
            <template #prefix>
              <el-icon style="color: brown"><Lock/></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item>
         <el-button style="margin-left:100px;width: 50%;" type="primary" @click="register">注册</el-button>
        </el-form-item>
      </el-form>
    </div>

  </div>
  <div style="position: relative">
    <video  autoplay loop preload style="width: 100%;position:relative;bottom: 100vh;z-index: -1;">
      <source :src="videoUrl">
    </video>
  </div>
</template>

<script>
import { User ,Lock } from '@element-plus/icons-vue'
import request from "@/utils/request";


export default {
  name: "Register",
  components: {Lock, User},
  data(){
    return{
      videoUrl:require('../assets/css/video1.mp4'),
      form:{},
      //验证用户名和密码是否输入
      rules:{
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
        confirm: [
          { required: true, message: '请确认密码', trigger: 'blur' }
        ],
      }
    }
  },
  methods:{
    register(){
      //判断两次输入密码
      if (this.form.password !== this.form.confirm){
        this.$message({
          type:"error",
          message:"2次输入密码不一致"
        })
        return
      }
      request.post("/api/user/register",this.form).then(res => {
        if(res.code ==='0'){
          console.log(this.form)
        this.$message({
            type:"success",
            message:"注册成功"
          })
          this.$router.push("/")  //登录成功之后进行页面跳转到主页
        } else {
          this.$message({
            type:"error",
            message:res.msg
          })
        }
      })

      }


    }

}
</script>

<style scoped>

</style>